package com.young.shop.admin.service.impl;

import com.young.shop.admin.dao.DataMapper;
import com.young.shop.admin.service.DataService;
import com.young.shop.pojo.vo.CenterDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;


@Service
public class DataServiceImpl implements DataService {

    @Autowired
    private DataMapper dataMapper;

    @Override
    public CenterDataVO getAllInfo() {

        CenterDataVO centerDataVO = new CenterDataVO();

        //查询付款订单数，付款金额，待处理订单
        CenterDataVO orderItem = dataMapper.selectTodayOrder();
        //当日订单数
        Integer orderNum = orderItem.getOrderNum();
        centerDataVO.setOrderNum(orderNum);
        //当日订单金额
        BigDecimal totalPrice = orderItem.getTotalPrice();
        centerDataVO.setTotalPrice(totalPrice);

        //查询商品总数
        Long goodsNumber = (long)dataMapper.selectGoodsNumber();
        centerDataVO.setTotalGoodsNumber(goodsNumber.intValue());

        //查询待处理订单数
        Long waitingGoodsNumber = (long)dataMapper.selectWaitingGoodsNumber();
        centerDataVO.setWaitingOrder(waitingGoodsNumber.intValue());

        //查询在售商品数
        Long onSaleGoodsNumber = (long)dataMapper.selectOnSaleGoodsNumber();
        centerDataVO.setOnSaleGoodsNumber(onSaleGoodsNumber.intValue());

        //查询库存不足商品数，
        Long underStockGoodsNumber = (long)dataMapper.selectUnderStockGoodsNumber();
        centerDataVO.setUnderStockGoodsNumber(underStockGoodsNumber.intValue());

        //查询当日商品浏览量
        Integer goodsViews = (Integer)dataMapper.selectGoodsViews();
        centerDataVO.setGoodsViews(goodsViews);

        return centerDataVO;
    }

    @Override
    public List<CenterDataVO> getCountByHours() {
        List<CenterDataVO> centerDataVOS = dataMapper.selectTodayData();
        return centerDataVOS;
    }

    @Override
    public List<CenterDataVO> getViewsByDate() {
        List<CenterDataVO> centerDataVOS = dataMapper.selectViewsData();
        return centerDataVOS;
    }
}
